﻿@page "/8th"
@page "/Anniversaries"
@page "/8th/{Type}"
@page "/Anniversaries/{Type}"

@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager
@implements IDisposable

<div class="anniversary-page">
    <CnGalWebSite.Shared.MasaComponent.Shared.Cards.TitleTip Title="@("周年庆"+Type switch {"Rating"=>" - 评选","Vote"=> " - 投票","Lottery" =>" - 抽奖","Introduction"=>"介绍",_=>""})" />
    <MDCard Class="mb-4">
        <MTabs Value="index" ValueChanged="IndexChanged" IconsAndText Grow CenterActive>
            <MTab Value="1">
                主页<MIcon>mdi-home</MIcon>
            </MTab>
            @*<MTab Value="2">
            评选<MIcon>mdi-star</MIcon>
            </MTab>*@
            <MTab Value="3">
                晒出你的游戏库<MIcon>@IconType.Game.ToIconString()</MIcon>
            </MTab>
            <MTab Value="4">
                抽奖<MIcon>mdi-wallet-giftcard</MIcon>
            </MTab>
            <MTab Value="5">
                活动介绍<MIcon>mdi-av-timer</MIcon>
            </MTab>
        </MTabs>
        </MDCard>

    <MTabsItems @bind-Value="index">
        <MTabItem Value="1">
            <CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.HomeCard />
        </MTabItem>
        <MTabItem Value="2">
            <CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.Ratings.IntroductionCard />
            <CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.Ratings.RandomUserScoreGroup />
            <CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.Ratings.GameGroup />
        </MTabItem>
        <MTabItem Value="3">
            <CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.PlayedGames.MainCard />
        </MTabItem>
        <MTabItem Value="4">
            <CnGalWebSite.Shared.Pages.Webs.Lotteries.Index Id="10" />
        </MTabItem>
        <MTabItem Value="5">
            <CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.Home.IntroductionCard />
        </MTabItem>
    </MTabsItems>

</div>


@code {
    [Parameter]
    public string Type { get; set; }

    StringNumber index = 0;
    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            NavigationManager.LocationChanged -= LocationChanged;
            NavigationManager.LocationChanged += LocationChanged;
        }
    }

    protected override void OnInitialized()
    {

        LocationChanged(null, null);

    }

    public void LocationChanged(object sender, LocationChangedEventArgs args)
    {
        index = Type switch
        {
            "Home" => 1,
            "Rating" => 2,
            "PlayedGames" => 3,
            "Lottery" => 4,
            "Introduction" => 5,
            _=>1
        };
        StateHasChanged();

    }

    public async void IndexChanged(StringNumber value)
    {
        index = value;

        string baseStr;

        if (NavigationManager.Uri.Contains("8th"))
        {
            baseStr = "8th";


        }
        else
        {
            baseStr = "Anniversaries";

        }

        NavigationManager.NavigateTo($"/{baseStr}/" + (index.ToInt32() switch
        {
            1 => "Home",
            2 => "Rating",
            3 => "PlayedGames",
            4 => "Lottery",
            5 => "Introduction",
            _ => ""
        }));

    }

    #region 释放实例

    public void Dispose()
    {

        NavigationManager.LocationChanged -= LocationChanged;

        GC.SuppressFinalize(this);
    }
    #endregion
}
